<?php

// use Illuminate\Support\Facades\Schema;
use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitVisitors extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('visitors', function (Blueprint $table) {
            $table->comment = '访客记录表';
            
            $table->increments('id');
            $table->uuid('uuid')->index();

            $table->integer('user_id')->unsigned()->index()->nullable();

            $table->text('origin')->nullable()->comment('来源信息');
            $table->text('user')->nullable()->comment('用户信息');
            $table->text('tenant')->nullable()->comment('商户信息');
            $table->text('wechat')->nullable()->comment('微信授权信息');
            $table->string('wechat_sex', 2)->nullable()->comment('性别');
            $table->string('ip', 128)->nullable()->comment('ip');

            $table->string('country', 50)->nullable()->comment('国家');
            $table->string('province', 50)->nullable()->comment('省');
            $table->string('city', 50)->nullable()->comment('市');

            $table->text('page')->nullable()->comment('访问页面');
            $table->text('client')->nullable()->comment('用户端信息');
            $table->text('device')->nullable()->comment('设备信息');
            $table->text('platform')->nullable()->comment('设备系统信息');
            $table->text('browser')->nullable()->comment('浏览器信息');
            $table->text('share_by')->nullable()->comment('是否被转发邀请而来');
            $table->string('app', 20)->index()->nullable();

            $table->string('client_type', 20)->index()->nullable()->comment('用户端类型');

            $table->timestamp('visit_at')->nullable()->index()->comment('访问时间');

            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('visitors');
    }
}
